//
// Created by hsx on 2025/4/14.
//

#include "connect_manager.h"

ConnectManager *ConnectManager::getInstance()
{
    static ConnectManager instance;
    return &instance;
}

bool ConnectManager::initUdp()
{
    // init返回非零为连接失败
    while (1)
    {
        if (AutoCmdClient.init(remoteAddr, AutoCmdPort) != 0 || agentServer.init(localAddr, localReportPort) != 0)
        {
            mp_log_error(DEFAULT_LOGGER, "UDP Connect failed");
        }
        else
        {
            mp_log_info(DEFAULT_LOGGER, "UDP Connect Success");
            std::string test = "通信正常";
            AutoCmdClient.send_message(test);
            break;
        }
    }
    agentServer.add_recv_over_callback([&](const std::string &remote_host, int remote_port, std::string &msg)
    { 
        // TODO
           
    });

    return true;
}